package com.nbsaas.boot;

import org.jdbi.v3.core.Jdbi;

import java.util.List;

/**
 * Hello world!
 *
 */
public class App {
    public static void main(String[] args) {

        try {
            Jdbi jdbi = Jdbi.create("jdbc:h2:mem:test"); // (H2 in-memory database)
            jdbi.useHandle(handle -> {
                handle.execute("create table contacts (id int primary key, name varchar(100))");
                handle.execute("insert into contacts (id, name) values (?, ?)", 1, "Alice");
                handle.execute("insert into contacts (id, name) values (?, ?)", 2, "Bob");
            });

            List<String> names = jdbi.withHandle(handle ->
                    handle.createQuery("select name from contacts")
                            .mapTo(String.class)
                            .list());

            System.out.println( names);
        }catch (Exception e){
               e.printStackTrace();
        }


        System.out.println( "Hello World!");
    }
}
